<?php


namespace app\common\model\mysql;


use think\Model;

class BaseModel extends Model
{
//自动写入时间
    protected $autoWriteTimestamp = true;


    /**
     * 根据主键ID 更新数据表里的数据
     * @param $id
     * @param $data
     * @return bool
     */
    public function updateById($id, $data)
    {
        $id = intval($id);
        if (empty($id) || empty($data) || !is_array($data)) {
            return false;
        }
        $data['update_time'] = time();
        $where = [
            "id" => $id,
        ];

        return $this->where($where)->save($data);
    }

    //根据id 获取SKU表数据
    public function getNormalInIds($ids)
    {
        return $this->whereIn("id", $ids)
            ->where("status", "=", config("status.mysql.table_normal"))
            ->select();
    }

    //根据条件 获取数据
    public function getByCondition($condition = [], $order = ["id" => "dsec"])
    {
        if (!$condition || !is_array($condition)) {
            return false;
        }
        $result = $this->where($condition)
            ->order($order)
            ->select();
        return $result;
    }

}